package com.guxingke.gblog.service.impl;

import java.util.List;

import com.guxingke.gblog.dao.MsgDao;
import com.guxingke.gblog.dao.impl.MsgDaoImpl;
import com.guxingke.gblog.dmo.Msg;
import com.guxingke.gblog.dto.MsgDto;
import com.guxingke.gblog.service.MsgService;
import com.guxingke.gblog.util.RegexpCheckUtils;

public class MsgServiceImpl implements MsgService {
	private MsgDao msgDao = null;

	public MsgServiceImpl() {
		msgDao = new MsgDaoImpl();
	}

	@Override
	public List<MsgDto> getComments(int articleId) {

		List<MsgDto> msgs = null;
		try {
			msgs = this.msgDao.getComments(articleId);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return msgs;
	}

	@Override
	public List<MsgDto> getLeaveMsgs() {

		List<MsgDto> msgs = null;
		try {
			msgs = this.msgDao.getLeaveMsgs();
		} catch (Exception e) {
			e.printStackTrace();
		}

		return msgs;
	}

	@Override
	public void saveMsg(Msg msg) {

		try {
			msg.setContent(RegexpCheckUtils.badFilter(RegexpCheckUtils.htmlRemoveTag(msg.getContent())));
			this.msgDao.save(msg);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	@Override
	public void deleteMsg(int id) {

		try {
			this.msgDao.delete(id);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	@Override
	public List<MsgDto> getRecentMsgs() {

		List<MsgDto> results = null;
		try {
			results = this.msgDao.getRecentMsgs();
		} catch (Exception e) {
			e.printStackTrace();
		}

		return results;
	}

	@Override
	public List<MsgDto> getAll() {

		List<MsgDto> results = null;
		try {
			results = this.msgDao.all();
		} catch (Exception e) {
			e.printStackTrace();
		}

		return results;
	}

}
